//
//  CABasicAnimationExtension.swift
//  Lottery
//
//  Created by 薛永伟 on 2019/2/14.
//  Copyright © 2019年 薛永伟. All rights reserved.
//

import UIKit

extension CABasicAnimation {
    
    ///
    struct Custom {
        
        /// 选择箭头旋转180度
        static func flip(isSelected:Bool) -> CABasicAnimation{
            let animationRotation = CABasicAnimation.init()
            animationRotation.keyPath = "transform.rotation.x"
            animationRotation.toValue = isSelected ? CGFloat.pi : 0
            animationRotation.duration = 0.3
            animationRotation.speed = 1
            animationRotation.fillMode = CAMediaTimingFillMode.forwards
            animationRotation.isRemovedOnCompletion = false
            animationRotation.timingFunction = CAMediaTimingFunction.init(name: CAMediaTimingFunctionName.easeInEaseOut)
            return animationRotation
        }
        
        /// 旋转动画
        static func rotating() -> CABasicAnimation {
            let ani = CABasicAnimation.init(keyPath: "transform.rotation.z")
            ani.toValue = CGFloat.pi*2
            ani.isRemovedOnCompletion = false
            ani.fillMode = .forwards
            ani.repeatCount = 10
            ani.duration = 2
            return ani
        }
        
    }
}
